package com.sailfish.springbootdemo.controller.db4;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.service.db4.UserService;
import com.sailfish.springbootdemo.utils.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/getUserListByDept")
    public Result getUserListByDept(Integer deptId) {
        return userService.getUserByDept(deptId);
    }

    @PostMapping("/login")
    public Result<?> login(String userName, String password, HttpServletRequest request) {
        String ipAddress = CommonUtils.getClientIpAddress(request);
        System.out.println("ipAddress=" + ipAddress);
        return userService.login(userName, password, ipAddress);
    }
}
